package com.license.rsa;

import java.net.URLDecoder;
import java.util.Date;

public class RSALicenseManager {
    private static byte[] encodedData = null;
    private static final String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCO+gxF66sEXrMmARaOiJgK+BXgkWcNzAJOkWyTkG3xjYQ6RAA2JR30jaCBWfDEKYfEDBaAN0m8Pr0nIsHRwwnqv58g5kxFdBBFkn8JB5iiC0pwzYF9ZW/lQUjjN8JRy1beOihbtYq5zMfzd5btUuXiITtUFAr0Hs+qtfUnw7Yg9wIDAQAB";

    static {
        try {
            String path = URLDecoder.decode(RSALicenseManager.class.getResource("/").getPath(), "UTF-8");
            encodedData = Base64Utils.fileToByte(path + "license.mes");
        } catch (Exception var1) {
            var1.printStackTrace();
        }
    }

    public static boolean validate() {
        try {
            String target = new String(RSAUtils.decryptByPublicKey(encodedData, publicKey));
            String[] arr = target.split(";");
            String serialNumber = SerialUtil.getMD5SerialNumber();
            System.out.println("机器序列号：" + serialNumber);
            return arr[0].equals(serialNumber) && (new Date()).getTime() < Long.parseLong(arr[1]);
        } catch (Exception var2) {
            var2.printStackTrace();
            return false;
        }
    }
}
